import GParam from '../../Core/GEvent/GParam';
import { CMsg, ITEM_TYPE } from '../Common/Define';
import GameMgr from "../Logic/GameMgr";
import { GCtrl } from './../../Core/GCtrl';

if (CC_DEV || CC_EDITOR) {
    window['WD_DEBUG'] = true;
}

if (CC_DEBUG || CC_DEV || CC_JSB) {
    if (window['WD_DEBUG']) {
        window['jx'] = GameMgr;
    }
    else {
        cc.log = function () { }

    }
    if (window['WD_DEBUG']) {
        window['jc'] = cc;
    }
    else {
        cc.log = function () { }
    }

    window['helps'] = () => {
        console.log("GM指令如下：")
        console.log("addItem([物品ID, 物品类型, 物品数量],...)");
        console.log("addHero(英雄ID) 添加英雄");
        console.log("exportLevelInfo() 导出关卡的位子信息")
    }

    window["addHero"] = (heroId: number) => {
        GCtrl.ES.emit(CMsg.client.hero.onAddHero, heroId)
    }

    window["lvUpEquip"] = (equip: string, lv: number) => {
        let info: EquipAddInfo = {
            equipId: equip,
            exp: lv
        }
        GCtrl.ES.emit(CMsg.client.equip.onAddEquipSlv, new GParam(info))
    }

    window["heroAddEquip"] = (equip: string, hero: number, site: number) => {
        let info: EquipPutInfo = {
            equipId: equip,
            heroId: hero,
            site: site
        }
        GCtrl.ES.emit(CMsg.client.equip.onEquipPutOn, new GParam(info))
    }

    window["heroBattle"] = (heroId: number[]) => {
        GameMgr.lUserData.heroInBattle = heroId
    }

    window["passGuide"] = () => {
    }

    window["addHeroChip"] = (heroId: number) => {
        let unlockStar = GameMgr.heroData.getRaw<SHeroDataRaw>(heroId).unlockStar;
        GCtrl.ES.emit(CMsg.client.bag.onBagItemChange, [[heroId, ITEM_TYPE.PROP, unlockStar]])
    }

    window["addItem"] = (itemId: number, type: number, num: number) => {
        GCtrl.ES.emit(CMsg.client.bag.onBagItemChange, [[itemId, type, num]]);
    }

    window["exportLevelInfo"] = () => {
        GCtrl.ES.emit(CMsg.client.test.export);
    }

    window["addLevel"] = () => {
        let level = GameMgr.lUserData.level;
        level++;
        GameMgr.lUserData.level = level;
    }


    window["clean"] = () => {
        GameMgr.ins().restart()
    }
    window["passGuide"] = () => {
        GameMgr.guideChainData.data.forEach((data: SGuideChainDataRaw, key: string) => {
            GameMgr.lUserData.setGuides(data.guideId)
        })
    }
}